//
//  Complex0.cpp
//  Practice11
//
//  Created by 赵世杰 on 2020/7/26.
//  Copyright © 2020 zhaoshijie. All rights reserved.
//

#include "Complex0.hpp"


Complex0 :: Complex0()
{
    x = y = 0;
}

Complex0 :: Complex0(double xx,double yy)
{
    x = xx;
    y = yy;
}

Complex0 Complex0:: operator + (const Complex0 & complex) const
{
    Complex0 com ;
    com.x = x+complex.x;
    com.y = y+complex.y;
    
    return com;
    
}


Complex0 Complex0:: operator - (const Complex0 & complex) const
{
    Complex0 com ;
    com.x = x-complex.x;
    com.y = y-complex.y;
    
    return com;
    
}



Complex0 Complex0:: operator * (const Complex0 & complex) const
{
    Complex0 com ;
    com.x = x*complex.x - y*complex.y;
    com.y = x*complex.y + y*complex.x;
    
    return com;
    
}



Complex0 Complex0:: operator * (double n) const
{
    Complex0 com ;
    com.x = x*n;
    com.y = y*n;
    
    return com;
    
}


Complex0 operator * (double n, const Complex0 & complex)
{
    
    Complex0 com ;
    com.x = complex.x*n;
    com.y = complex.y*n;
    
    return com;
    
}


std::istream & operator >>(std::istream & os , Complex0 &com)
{
    
    double xx;
    double yy;
    
    cout << "请输入x: " ;
    cin >> xx;
    
    cout << "请输入y: " ;
    cin >> yy;
    
    com.x = xx;
    com.y = yy;
    
    
    return os;
}

std::ostream & operator <<(std::ostream & os , const Complex0 &com)
{
    cout << "x: " << com.x << "  y: " << com.y << endl;
    
    return os;
    
}
